<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>预收账款列表</title>
    <script type="text/javascript">
      var newAdvanceWin;
      var editAdvanceWin;
      var advanceId;
      Ext.onReady(function(){
        //预收账款设置---------------------------------------------------------
        //生成有关预收账款的Grid
        var advanceDS = new Ext.data.Store({
          proxy: new Ext.data.HttpProxy({
            url: '/advance_payment/getAllAdvancePayments'
          }),
          reader: new Ext.data.JsonReader({
            totalProperty: 'totalProperty',
            root: 'root'
          }, [{
              name: 'id'
            }, {
              name: 'customer_name',
              mapping: 'customer.name'
            }, {
              name: 'action_date'
            }, {
              name: 'bank_name'
            }, {
              name: 'account'
            }, {
              name: 'amount'
            }, {
              name: 'percent'
            }, {
              name: 'employee_name',
              mapping:'employee.name'
            }, {
              name: 'description'
            }, {
              name: 'created_at'
            }, {
              name: 'updated_at'
            }])
        });
        var advanceSM = new Ext.grid.CheckboxSelectionModel();
        var advanceCM = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(),advanceSM,{
            header: 'id',
            dataIndex: 'id',
            width: 30
          }, {
            header: '客户名称',
            dataIndex: 'customer_name',
            width:230
          },{
            header: '汇入时间',
            dataIndex: 'action_date',
            renderer: Ext.util.Format.dateRenderer('Y-m-d'),
            width: 80
          },{
            header: '开户行',
            dataIndex: 'bank_name',
            width: 60
          }, {
            header: '账号',
            dataIndex: 'account',
            width:160
          }, {
            header: '金额',
            dataIndex: 'amount',
            align: 'right',
            renderer: Ext.util.Format.numberRenderer('0,000.00'),
            width:60
          }, {
            header: '返利比例',
            dataIndex: 'percent',
            width:60
          }, {
            header: '操作员',
            dataIndex: 'employee_name',
            width:90
          }, {
            header: '描述',
            dataIndex: 'description',
            width:330
          },{
            header: '生成日期',
            dataIndex: 'created_at',
            renderer: Ext.util.Format.dateRenderer('Y-m-d H:i'),
            width: 100
          },{
            header: '修改日期',
            dataIndex: 'updated_at',
            renderer: Ext.util.Format.dateRenderer('Y-m-d H:i'),
            width: 100
          }]);
        var advanceGrid =  new Ext.grid.GridPanel({
          ds: advanceDS,
          cm: advanceCM,
          sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
          width: screenWidth-330,
          height: screenHeight-380,
          iconCls: 'icon-grid',
          loadMask: true,
          //collapsible: true,
          //animCollapse: false,
          //frame: true,
          //title: '预收账款列表',
          bbar: new Ext.PagingToolbar({
            pageSize: 10,
            store: advanceDS,
            displayInfo: true,
            displayMsg: "显示第 {0} 条到 {1} 条记录，一共 {2} 条",
            emptyMsg: "没有记录"
          }),
          tbar: [{
              text: '添加',
              iconCls: 'addItem',
              handler : function(){
                newAdvanceWin = new Ext.Window({
                  layout: 'fit',
                  width:618,
                  height:260,
                  closeAction: 'destroy',
                  plain: true,
                  modal: true,
                  constrain:true,
                  //modal: true,
                  title: '添加预收账款',
                  autoLoad: {
                    url: "/advance_payment/newAdvance",
                    scripts: true
                  }
                });
                newAdvanceWin.on("destroy",function(){
                  advanceDS.reload();
                });
                newAdvanceWin.resizable = false;
                newAdvanceWin.show();
              }
            },"-",{
              text: '编辑',
              iconCls: 'editItem',
              handler : function(){
                var records = advanceGrid.getSelectionModel().getSelections();
                if(records.length==0){
                  Ext.MessageBox.show({
                    title: '提示信息',
                    msg: "请先选中一条记录后，再编辑。",
                    buttons: Ext.MessageBox.OK,
                    icon: Ext.MessageBox.WARNING
                  });
                }else{
                  //把表单添加到窗口中
                  advanceId = records[0].get('id');
                  editAdvanceWin = new Ext.Window({
                    title: '编辑预收账款',
                    layout:'fit',
                    width:618,
                    height:260,
                    closeAction:'destroy',
                    constrain:true,
                    plain: true,
                    modal: true,
                    autoLoad: {
                      url: "/advance_payment/editAdvance?id=" + advanceId,
                      scripts: true
                    }
                  });
                }
                editAdvanceWin.on("destroy",function(){
                  advanceDS.reload();
                });
                editAdvanceWin.resizable = false;
                editAdvanceWin.show();
              }
            }]
        });
        advanceGrid.render('advance_list');
        advanceDS.load();
      })
    </script>
  </head>
  <body>
    <div id="advance_list"></div>
  </body>
</html>
